﻿#include "LEData.h"
#include <QDebug>
LEData::LEData()
{
    m_data.clear();
}


void LEData::loadFromSettings(QSettings &settings, QString prefix)
{
    m_data.clear();
    qDebug() << prefix + "Count";
    int count = settings.value(prefix + "Count", 0).toInt();
    qDebug() << count;
    for(int i = 0; i < count; i++)
    {
        QString key = QString("%1%2").arg(prefix).arg(i);
        bool ok;
        double v = settings.value(key, 0).toDouble(&ok);
        if(ok)
        {
            m_data.append(v);
        }
    }
    qDebug() << m_data;
}

void LEData::writeToSettings(QSettings &settings, QString prefix)
{
    int count = m_data.size();
    settings.setValue(prefix + "Count", count);
    if(count > 1)
    {
        for(int i = 0; i < count; i++)
        {
            QString key = QString("%1%2").arg(prefix).arg(i);
            settings.setValue(key, m_data[i]);
        }
    }
}

void LEData::clear()
{
    m_data.clear();
}

bool LEData::append(double x)
{
    if(x < 0) return false;
    m_data.append(x);
    return true;
}

void LEData::transfer(LECalibrator *cal)
{
    cal->loadPoints(m_data);
}
